package com.easy.work.function.me.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.work.R;
import com.easy.work.bean.WithdrawBean;
import com.easy.work.function.me.CashDrawActivity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2018/1/2.
 * 提现
 */
public class CashDrawAdapter extends BaseAdapter {
    private Context mCtx;
    ViewGroup.MarginLayoutParams marginParams;
    List<WithdrawBean> withdrawBeenList = new ArrayList<>();

    public CashDrawAdapter(Context context, List<WithdrawBean> withdrawBeenList) {
        this.mCtx = context;
        this.withdrawBeenList = withdrawBeenList;
    }

    @Override
    public int getCount() {
        return withdrawBeenList.size();
    }

    @Override
    public Object getItem(int position) {
        return withdrawBeenList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_cash_draw, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final WithdrawBean bean = withdrawBeenList.get(position);

        Picasso.with(mCtx).load(bean.companyImage).error(R.mipmap.icon_zhaopintiaojian).into(viewHolder.ivCompany);
        viewHolder.tvEmployCompany.setText("录用公司：" + bean.companyName);
        viewHolder.tvEmployTime.setText("录用时间：" + bean.employedDate);
        viewHolder.tvDrawMoney.setText("提现金额：" + bean.cashBackNum + "元");
        viewHolder.tvStatus.setText("提现状态：" + bean.statusText);
        if (bean.status == -1 || bean.status == 3) {
            viewHolder.btnStatus.setBackgroundResource(R.drawable.drawable_login);
        } else {
            viewHolder.btnStatus.setBackgroundResource(R.drawable.corner_bg_gray);
        }

        viewHolder.btnStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (bean.status == -1) {
                    CashDrawActivity.start(mCtx, bean);
                }
            }
        });
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_company)
        ImageView ivCompany;
        @BindView(R.id.tv_employ_company)
        TextView tvEmployCompany;
        @BindView(R.id.tv_employ_time)
        TextView tvEmployTime;
        @BindView(R.id.tv_draw_money)
        TextView tvDrawMoney;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.btn_status)
        Button btnStatus;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
